﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

//键盘行
//https://leetcode.cn/problems/keyboard-row/
class Solution {
public:
    //检验单词是否在这一行
    bool insp(bitset<123>& line,const string& s)
    {
        for(const auto& c:s)
            if(!line.test(c)) return false;
        
        return true;
    }

    vector<string> findWords(vector<string>& words) {
        vector<string> ret;
        vector<string> vs = {"qwertyuiopQWERTYUIOP","asdfghjklASDFGHJKL","zxcvbnmZXCVBNM"};
        bitset<123> line1;
        bitset<123> line2;
        bitset<123> line3;
        for(const auto& c:vs[0]) line1.set(c);
        for(const auto& c:vs[1]) line2.set(c);
        for(const auto& c:vs[2]) line3.set(c);

        for(const auto& s:words)
        {
            char c = s[0];
            if(line1[c] && insp(line1,s)) //在第一行
                ret.push_back(s);
            else if(line2[c] && insp(line2,s)) //在第二行
                ret.push_back(s);
            else if(insp(line3,s))//在第三行
                ret.push_back(s);
        }

        return ret;
    }
};

//宝石与石头
//https://leetcode.cn/problems/jewels-and-stones/description/
class Solution {
public:
    int numJewelsInStones(string jewels, string stones) {
        bitset<123> bs;
        for(const auto& c:jewels) bs.set(c);

        int count = 0;
        for(const auto& c:stones)
            if(bs.test(c)) ++count;

        return count;
    }
};


